home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / pcl4c60.zip / DOOR.C < prev    next >
Text File  |  1996-10-10  |  2KB  |  90 lines

  1. /*
  2. **   DOOR.C  (11/07/95)
  3. **
  4. **   EXAMPLE CODE: Gain control w/o resetting UART.
  5. **
  6. **   (1) Make sure that SPAWN.EXE and DOOR.EXE are both
  7. **       in the current directory.
  8. **   (2) Start the companion program SPAWN.
  9. **   (3) Within SPAWN, type '$' to request that DOOR.EXE be
  10. **       spawned. DOOR will "take over" the COM port without
  11. **       resetting the UART or dropping the modem carrier.
  12. **   (4) When done, exit this program, then type EXIT to
  13. **       return to SPAWN.
  14. **
  15. **   For more information, see documentation.
  16. **
  17. **   This example program (not the PCL4C library) is donated to
  18. **   the Public Domain by MarshallSoft Computing, Inc. It is
  19. **   provided as an example of the use of the PCL4C.
  20. **
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <dos.h>
  26. #include <string.h>
  27. #include <conio.h>
  28. #include "pcl4c.h"
  29.  
  30. #define FALSE 0
  31. #define TRUE !FALSE
  32. #define CTLZ    0x1a
  33. #define BUFSIZE 64
  34.  
  35. /*** Global Variables ***/
  36.  
  37. static char RxBuffer[BUFSIZE+16];
  38. static char TxBuffer[BUFSIZE+16];
  39. static int Port;
  40.  
  41. /*** Main ***/
  42.  
  43. int main(int argc,char *argv[])
  44. {char c;
  45.  char *ptr;
  46.  int  i, rc;
  47.  int  Seg;
  48.  char far *Ptr;
  49.  /* get comm port */
  50.  if(argc!=2)
  51.    {printf("DOOR: Usage: 'DOOR <port>' \n");
  52.     return 1;
  53.    }
  54.  /* get port number from command line */
  55.  Port = atoi(argv[1]) - 1;
  56.  if((Port<COM1) || (Port>COM20)) return 1;
  57.  printf("DOOR: COM%d\n",1+Port);
  58.  /* setup 128 byte receive buffer */
  59.  Ptr = (char far *)RxBuffer;
  60.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  61.  SioRxBuf(Port,Seg,Size128);
  62.  /* setup 128 byte transmit buffer */
  63.  Ptr = (char far *)TxBuffer;
  64.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  65.  SioTxBuf(Port,Seg,Size128);
  66.  /* take over the port */
  67.  SioReset(Port,NORESET);
  68.  /* DTR & RTS will be the same as before calling SioReset */
  69.  printf("DOOR: COM%d [DTR=%d]\n",1+Port,SioDTR(Port,'R'));
  70.  printf("DOOR: Type ^Z to return to invoking program !\n");
  71.  /* enter terminal loop */
  72.  while(TRUE)
  73.      {/* was key pressed ? */
  74.       if(kbhit())
  75.           {i = getch();
  76.            if((char)i==CTLZ)
  77.               {/* restore COM port status & exit */
  78.                SioDone(Port);
  79.                printf("DOOR: Exiting...\n");
  80.                return 0;
  81.               }
  82.            else SioPutc(Port,(char)i);
  83.           } /* end if */
  84.       /* any incoming over serial port ? */
  85.       i = SioGetc(Port,0);
  86.       if(i>-1) putch((char)i);
  87.      } /* end while */
  88. } /* end main */
  89.  
  90.